#!/bin/bash

# CC测试服 通过api_test可直接命令发送测试消息 $curl -X POST "http://127.0.0.1:5013/tgbot/api" -d"{'msg_type':'1','msg_text':'qwe321523'}"

# 提示用户输入Bot令牌
echo "请输入您的Bot_token:"
read -r BOT_TOKEN

# 检查输入是否为空
if [ -z "$BOT_TOKEN" ]; then
    echo "错误: Bot令牌不能为空"
    exit 1
fi

#echo "正在获取聊天消息..."

# 使用getUpdates方法获取最新消息数据
response=$(curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/getUpdates")

#echo "API响应:"
#echo "$response"
#echo ""

# 解析并提取chat id
echo "提取的Chat ID列表:"
echo "$response" | grep -o '"chat":{"id":[^,]*' | grep -o '\-\?[0-9]\+' | sort -u
